package com.rookieci.totp;

import android.app.Application;
import android.os.Handler;

import com.rookieci.lib.LibApp;

import java.util.concurrent.Executor;
import java.util.concurrent.ScheduledThreadPoolExecutor;

/**
 * Created by 磁磁帅 on 2025/8/10 0010.
 * 功能：
 */
public class TotpApp extends Application {
    private static TotpApp totpApp;

    public static TotpApp getInstance() {
        return totpApp;
    }

    private Executor executor;

    public static Handler getHandler() {
        return LibApp.getHandler();
    }

    public static void runOnUiThread(Runnable runnable) {
        if (runnable == null) return;
        getHandler().post(runnable);
    }

    public static void runOnUiThread(Runnable runnable, long delayMillis) {
        if (runnable == null) return;
        getHandler().postDelayed(runnable, delayMillis);
    }

    public static void runThread(Runnable runnable) {
        if (runnable == null) return;
        getInstance().getExecutorService().execute(runnable);
    }

    public Executor getExecutorService() {
        return executor;
    }

    @Override
    public void onCreate() {
        super.onCreate();

        totpApp = this;
        LibApp.init(this);
        executor = new ScheduledThreadPoolExecutor(1);
    }
}
